package common.com.androidbase.datarequest;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.net.URLEncoder;

/**
 * 之前的：actionUrl
 *
 * @author kimwang
 */
public class ActionProtocol implements Parcelable {

    public static final int INNER_BLOWSER = 2;

    private long sid;
    private int urlFlag;
    private int action;
    private long cid;
    private long vid;
    private String url;
    private String cateCode;
    private String live_id;
    private int site;

    public ActionProtocol() {
    }

    public ActionProtocol(Parcel source) {
        sid = source.readLong();
        urlFlag = source.readInt();
        action = source.readInt();
        cid = source.readLong();
        vid = source.readLong();
        url = source.readString();
        cateCode = source.readString();
        live_id = source.readString();
        site = source.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(sid);
        dest.writeInt(urlFlag);
        dest.writeInt(action);
        dest.writeLong(cid);
        dest.writeLong(vid);
        dest.writeString(url);
        dest.writeString(cateCode);
        dest.writeString(live_id);
        dest.writeInt(site);
    }

    public static final Creator<ActionProtocol> CREATOR = new Creator<ActionProtocol>() {

        @Override
        public ActionProtocol[] newArray(int size) {
            return new ActionProtocol[size];
        }

        @Override
        public ActionProtocol createFromParcel(Parcel source) {
            return new ActionProtocol(source);
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    public int getSite() {
        return site;
    }

    public void setSite(int site) {
        this.site = site;
    }

    public String getLive_id() {
        return live_id;
    }

    public void setLive_id(String live_id) {
        this.live_id = live_id;
    }

    public long getSid() {
        return sid;
    }

    public void setSid(long sid) {
        this.sid = sid;
    }

    public int getUrlFlag() {
        return urlFlag;
    }

    public void setUrlFlag(int urlFlag) {
        this.urlFlag = urlFlag;
    }

    public int getAction() {
        return action;
    }

    public void setAction(int action) {
        this.action = action;
    }

    public long getCid() {
        return cid;
    }

    public void setCid(long cid) {
        this.cid = cid;
    }

    public long getVid() {
        return vid;
    }

    public void setVid(long vid) {
        this.vid = vid;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getCateCode() {
        return cateCode;
    }

    public void setCateCode(String cateCode) {
        this.cateCode = cateCode;
    }

    /**
     * 拼接成4.0以前的actionUrl
     *
     * @return
     */
    public String getActionUrl() {

        String action = String.valueOf(getAction());
        String actionUrl = "sva://action.cmd?action=" + action;
        if (action.contains(".")) {
            actionUrl = actionUrl + "&urls=" + URLEncoder.encode(getUrl());
        } else {
            actionUrl = actionUrl + "&url=" + URLEncoder.encode(getUrl());
        }

        StringBuffer sb = new StringBuffer(actionUrl);
        sb.append("&sid=").append(getSid()).append("&vid=").append(getVid()).append("&cid=").append(getCid())
                .append("&cateCode=").append(!TextUtils.isEmpty(getCateCode()) ? getCateCode() : "")
                .append("&live_id=").append(!TextUtils.isEmpty(getLive_id()) ? getLive_id() : "").append("&site=")
                .append(getSite()).append("&urlFlag=").append(getUrlFlag());
        return sb.toString();
    }

}
